﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dao;
using System.Data.SqlClient;
namespace 班级系统
{
    public partial class ClassSong : Form
    {
        Form frm;
        Student thou = new Student();
        public ClassSong(Form frm, Student thou)
        {
            InitializeComponent();
            this.frm = frm;
            this.thou = thou;
        }
        int x = 0;
        int count = 0;
        DataTable dt_logo;
        private void ClassSong_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[x];
            //TODO 加载初始班级数据

            //查询当前班级信息
            string className=thou.Form1S[2].ToString();
            string select = "select * from class where class_name=@className";
            SqlParameter[] para = new SqlParameter[]{
               new SqlParameter("className",className)
            };
            DataTable dt_class = sqlcontent.dt(select,para);
            DataRow class_detail = dt_class.Rows[0];

            //初始化班歌
            comboBox1.Items.Clear();
            string sql_song = "select song_name from song ";
            DataTable dt = sqlcontent.dt(sql_song);
            foreach (DataRow myrow in dt.Rows)
            {
                comboBox1.Items.Add(myrow[0]);
            }
            comboBox1.Text = class_detail["class_song"].ToString();
            //初始化班训
            richTextBox1.Text = "";
            if (class_detail["class_call"]!=null)
            {
                richTextBox1.Text = class_detail["class_call"].ToString();
            }
            //初始化班徽
            string sql_logo = "select * from logo";
            dt_logo = sqlcontent.dt(sql_logo);
            count = dt_logo.Rows.Count;
            this.pictureBox1.Load(dt_logo.Rows[i % count][1].ToString());
        }
        //下一张图片
        private void button2_Click(object sender, EventArgs e)
        {
            i++;
            //pictureBox1.Image = imageList1.Images[x % count];
            this.pictureBox1.Load(dt_logo.Rows[i % count][1].ToString());
        }

        //上一页
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
            frm.Show();
        }
        //下一步
        private void button4_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
            {
                MessageBox.Show("请选择班歌");
                return;
            }
            string[] form3s = new string[3];
            form3s[0] = comboBox1.Text;
            form3s[1] = richTextBox1.Text;
            form3s[2] = dt_logo.Rows[i % count][1].ToString();
            thou.Form3S = form3s;
            PictureBox m = this.pictureBox1;
            thou.pictureBox = m;
            Form4 frm4 = new Form4(this, thou);
            frm4.Show();
            this.Hide();
        }
        private int i = 0;
       
        private void button1_Click(object sender, EventArgs e)
        {

            OpenFileDialog openfile = new OpenFileDialog();
            if (openfile.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != "")
            {
                
                string sql = "insert into logo(logo_url) values(@logo_url)";
                SqlParameter[] para = new SqlParameter[]{
                    new SqlParameter("logo_url",openfile.FileName)
                };
                if (sqlcontent.content(sql,para)==0)
                {
                    MessageBox.Show("未能成功添加");
                    return;
                }
                sql = "select * from logo";
                dt_logo = sqlcontent.dt(sql);
                count = dt_logo.Rows.Count;
                //i = count - i;
                pictureBox1.Image = Image.FromFile(openfile.FileName);
              
                //pictureBox1.ImageLocation = openfile.FileName;
                //imageList1.Images.Add(pictureBox1.Image);
                //num++;
            }
            openfile.Dispose();
        }


    }
}
